package com.vonchange.common.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.vonchange.common.session.SessionUtil;
import com.vonchange.utils.web.RequestUtils;

@Controller
public class ResController {
	private final static Log logger = LogFactory.getLog(ResController.class);
	@RequestMapping("/config/config.js")
	public ModelAndView config(ModelAndView mav, HttpServletRequest request, HttpServletResponse response) {
		String url = RequestUtils.getUrl(request);
		mav.addObject("preURL", RequestUtils.getBaseLocation(request));
		mav.addObject("msgError", SessionUtil.getSession(request, SessionUtil.MSG_ERROR));
		mav.addObject("msgInfo", SessionUtil.getSession(request, SessionUtil.MSG_INFO));
		SessionUtil.setSesssion(request, SessionUtil.MSG_ERROR, null);
		SessionUtil.setSesssion(request, SessionUtil.MSG_INFO, null);
		mav.setViewName(url);
		logger.debug(url);
	    response.setContentType("application/x-javascript");
		return mav;
	}
	@RequestMapping("/config/config-{v}.js")
	public ModelAndView configMin(ModelAndView mav,@PathVariable(value="v") String v,HttpServletRequest request, HttpServletResponse response){
		mav.addObject("preURL", RequestUtils.getBaseLocation(request));
		mav.addObject("msgError",SessionUtil.getSession(request, SessionUtil.MSG_ERROR));
		mav.addObject("msgInfo",SessionUtil.getSession(request, SessionUtil.MSG_INFO));
		SessionUtil.setSesssion(request, SessionUtil.MSG_ERROR, null);
		SessionUtil.setSesssion(request, SessionUtil.MSG_INFO, null);
		mav.setViewName("config/config.js");
		response.setContentType("application/x-javascript");
		return mav;
	}

}
